import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.LinkedList;


public class Board {

	protected LinkedList<MainBall> mainBalls; //50 main balls
	protected LinkedList<LuckyBall> luckyBalls; //11 lucky balls
	protected DrawFactory df; //a draw factory
	protected LinkedList<Draw> draws; //all of the draws
	
	public Board()
	{
		mainBalls = new LinkedList<MainBall>();
		luckyBalls = new LinkedList<LuckyBall>();
		
		for(int i = 1; i <= 50; i++)
		{
			mainBalls.add(new MainBall(i));
		}
		
		for(int j = 1; j <= 11; j++)
		{
			luckyBalls.add(new LuckyBall(j));
		}
		df = new DrawFactory();
		df.createDraws();
		draws = df.getDraws();
	}
	
	public LinkedList<MainBall> getMains()
	{
		return mainBalls;
	}
	
	public LinkedList<LuckyBall> getLuckys()
	{
		return luckyBalls;
	}
	
 	public static void main(String[] args)
	{
		Board b = new Board();
		b.processDraws();
		
		int day = GregorianCalendar.TUESDAY;
		
		int odd1 = 0;
		int odd2 = 0;
		
		
		for(Ball ball: b.getMains())
		{
			odd1 += ball.getOccurance(day);
			ball.processDates(new GregorianCalendar());
			System.out.println("Main Ball Number: " + ball.getName() + ", occurance: " + ball.getOccurance(day) + ", odd is: " + ball.getOdd());
			
		}
		for(Ball ball: b.getLuckys())
		{
			odd2 += ball.getOccurance(day);
			ball.processDates(new GregorianCalendar());
			System.out.println("Lucky Ball Number: " + ball.getName() + ", occurance: " + ball.getOccurance(day) + ", odd is: " + ball.getOdd());
		}
		
		System.out.println("--------------------------------------------------------------------------------------------");
		System.out.println("Occurrance Odd Average: " + odd1/50 + ", and " + odd2/11);
		
		System.out.print("3D: ");
		for(Ball ball: b.getMains())
		{
			System.out.print("M"+ ball.getName() + ",");
			ball.processThreeD(day);
		}
		for(Ball ball: b.getLuckys())
		{
			System.out.print("L"+ ball.getName() + ",");
			ball.processThreeD(day);
		}
		System.out.println();
		
		/*
		System.out.print("4D: ");
		for(Ball ball: b.getMains())
		{
			System.out.print("M"+ ball.getName() + ",");
			ball.processFourD();
		}
		for(Ball ball: b.getLuckys())
		{
			System.out.print("L"+ ball.getName() + ",");
			ball.processFourD();
		}*/
		
		//System.out.println();
		
		System.out.print("5D: ");
		for(Ball ball: b.getMains())
		{
			System.out.print("M"+ ball.getName() + ",");
			ball.processFiveD(day);
		}
		for(Ball ball: b.getLuckys())
		{
			System.out.print("L"+ ball.getName() + ",");
			ball.processFiveD(day);
		}
		System.out.println();
		
		
		OddAnalyser mainAnalysis = new OddAnalyser();
		OddAnalyser luckyAnalysis = new OddAnalyser();
		mainAnalysis.setDay(day);
		luckyAnalysis.setDay(day);
		for(Ball ball: b.getMains())
		{
			mainAnalysis.insertBall(ball);
		}
		
		for(Ball ball: b.getLuckys())
		{
			luckyAnalysis.insertBall(ball);
		}
		
		mainAnalysis.printData(new GregorianCalendar());
		System.out.println("--------------------------------------------------------------------------------------------");
		luckyAnalysis.printData(new GregorianCalendar());
		System.out.println("--------------------------------------------------------------------------------------------");
	}
 	
 	public void processDraws()
 	{
 		long temp = 1;
 		for(Draw d : this.draws)
 		{
 			GregorianCalendar date = d.getDate();
 			for(MainBall mb: d.getMains())
 			{
 				MainBall m = mainBalls.get(mb.getName()-1);
 				m.addDate(date);
 				m.addOdd(temp);
 			}
 			for(LuckyBall lb: d.getLuckys())
 			{
 				LuckyBall l = luckyBalls.get(lb.getName()-1);
 				l.addDate(date);
 				l.addOdd(temp);
 			}
 			temp++;
 		}
 	}
}



